package com.hc.tenant.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hc.common.log.annotation.Log;
import com.hc.common.log.enums.BusinessType;
import com.hc.common.security.annotation.PreAuthorize;
import com.hc.tenant.domain.RobotSetting;
import com.hc.tenant.service.IRobotSettingService;
import com.hc.common.core.web.controller.BaseController;
import com.hc.common.core.web.domain.AjaxResult;
import com.hc.common.core.utils.poi.ExcelUtil;
import com.hc.common.core.web.page.TableDataInfo;

/**
 * 机器人设置Controller
 * 
 * @author yongjianz
 * @date 2021-03-27
 */
@RestController
@RequestMapping("/robotSetting")
public class RobotSettingController extends BaseController
{
    @Autowired
    private IRobotSettingService robotSettingService;

    /**
     * 查询机器人设置列表
     */
    @PreAuthorize(hasPermi = "tenant:robotSetting:list")
    @GetMapping("/list")
    public TableDataInfo list(RobotSetting robotSetting)
    {
        startPage();
        List<RobotSetting> list = robotSettingService.selectRobotSettingList(robotSetting);
        return getDataTable(list);
    }

    /**
     * 导出机器人设置列表
     */
    @PreAuthorize(hasPermi = "tenant:robotSetting:export")
    @Log(title = "机器人设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RobotSetting robotSetting) throws IOException
    {
        List<RobotSetting> list = robotSettingService.selectRobotSettingList(robotSetting);
        ExcelUtil<RobotSetting> util = new ExcelUtil<RobotSetting>(RobotSetting.class);
        util.exportExcel(response, list, "robotSetting");
    }

    /**
     * 获取机器人设置详细信息
     */
    @PreAuthorize(hasPermi = "tenant:robotSetting:query")
    @GetMapping(value = "/{robotId}")
    public AjaxResult getInfo(@PathVariable("robotId") Long robotId)
    {
        return AjaxResult.success(robotSettingService.selectRobotSettingById(robotId));
    }

    /**
     * 新增机器人设置
     */
    @PreAuthorize(hasPermi = "tenant:robotSetting:add")
    @Log(title = "机器人设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RobotSetting robotSetting)
    {
        return robotSettingService.insertRobotSetting(robotSetting);
    }

    /**
     * 修改机器人设置
     */
    @PreAuthorize(hasPermi = "tenant:robotSetting:edit")
    @Log(title = "机器人设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RobotSetting robotSetting)
    {
        return robotSettingService.updateRobotSetting(robotSetting);
    }

    /**
     * 删除机器人设置
     */
    @PreAuthorize(hasPermi = "tenant:robotSetting:remove")
    @Log(title = "机器人设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{robotIds}")
    public AjaxResult remove(@PathVariable Long[] robotIds)
    {
        return toAjax(robotSettingService.deleteRobotSettingByIds(robotIds));
    }
}
